import java.util.StringTokenizer;


class P11219_39643 {

	public static void main(String[] args) {

		int cases = Integer.parseInt(readLn());
		
		for (int k = 0; k < cases; k++) {
			readLn();
			System.out.print("Case #" + (k + 1) + ": ");
			process();
			
			
		}
		
	}
	
	private static void process() {
		
		StringTokenizer st = new StringTokenizer(readLn(), "/");
		
		int[] current = new int[3];
		
		current[0] = Integer.parseInt(st.nextToken());
		current[1] = Integer.parseInt(st.nextToken());
		current[2] = Integer.parseInt(st.nextToken());
		
		st = new StringTokenizer(readLn(), "/");
		
		int[] birth = new int[3];
		
		birth[0] = Integer.parseInt(st.nextToken());
		birth[1] = Integer.parseInt(st.nextToken());
		birth[2] = Integer.parseInt(st.nextToken());
		
//		current: dd / mm / yyyy
//		birth  : dd / mm / yyyy
		
		int age = current[2] - birth[2];
		
		if (current[1] < birth[1]) {
			age--;
		}
		
		if (current[1] == birth[1] && current[0] < birth[0]) {
			age--;
		}
		
		if (age < 0) {
			System.out.println("Invalid birth date");
		} else if (age > 130) {
			System.out.println("Check birth date");
		} else System.out.println(age);
		
		
		
	}

	static String readLn() {
        String newLine = System.getProperty("line.separator");
        StringBuffer buffer = new StringBuffer();
        int car = -1;
        try {
            car = System.in.read();
            while ((car > 0) && (car != newLine.charAt(0))) {
                buffer.append((char)car);
                car = System.in.read();
            }
            if (car == newLine.charAt(0))
            System.in.skip(newLine.length() - 1);
        } catch (java.io.IOException e) { return (null);}
        if ((car < 0) && (buffer.length() == 0)) return (null);
        return (buffer.toString());
    }

	
}
